package com.sc1.controller;

import com.sc1.pojo.HUser;
import com.sc1.pojo.Hdept;
import com.sc1.service.HUserService;
import com.sc1.service.impl.HUserServiceImpl;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.List;

@Controller
public class HUserController {
    HUserService HUS = new HUserServiceImpl();
    @RequestMapping("/home")
    public String home(HttpSession session) {
        return "/home";
    }

    @RequestMapping("/show")
    public String show(HttpSession session) {
        List<HUser> users= HUS.show();
        session.setAttribute("users", users);
        return "/show";
    }

    @RequestMapping("/toreg")
    public String toreg(HttpSession session) {
        return "/reg";
    }

    @RequestMapping("/reg")
    public String reg(HUser user, HttpSession session) {
        System.out.println(user.getUsername());
        System.out.println(user.getPassword());
        System.out.println(user.getDid());
        System.out.println(user.getinfo().getSex());
        System.out.println(user.getinfo().getAge());
        user.setCreatetime(new Date());
        HUS.insert(user);
        List<HUser> users= HUS.show();
        session.setAttribute("users", users);
        return "/show";
    }

    @RequestMapping("/ShowDept")
    public String ShowDept(HttpSession session){
        List<Hdept> depts = HUS.ShowDept();
        session.setAttribute("depts", depts);
        return "/showdept";
    }

    @RequestMapping("/deleteDept")
    public String deleteDept(HttpSession session,int id){
        HUS.deleteDeptById(id);
        return "forward:/ShowDept";
    }


}
